package cn.orange.ch01_array;

/**
 * LC27.移除元素
 */
public class LC27 {
    public int removeElement(int[] nums, int val) {
        int slow = 0;
        for (int fast = 0; fast < nums.length; fast++) {
            if (nums[fast] != val) {
                nums[slow++] = nums[fast];
            }
        }
        return slow;
    }

    public static void main(String[] args) {
        LC27 alg = new LC27();
        System.out.println(alg.removeElement(new int[]{3, 2, 2, 3}, 3));
        System.out.println(alg.removeElement(new int[]{0, 1, 2, 2, 3, 0, 4, 2}, 2));
    }
}
